import request from "@/utils/request";


// 登录
export const getLogin = (info) => {
  //return request.post("user/login", info)
  return request({
    method: "post",
    url: "user/login",
    data: info,
  });
};

//注册
export const register = (info) => {
  //return request.post("user/login", info)
  return request({
    method: "post",
    url: "user/register",
    data: info,
  });
};
//找回密码
export const resetAccount = (info) => {
  //return request.post("user/login", info)
  return request({
    method: "put",
    url: "user/resetAccount",
    data: info,
  });
};

//获取用户信息
export const getUser = () =>{
  return request({
      method:'get',
      url:'user/getUser'
  })
}

// 获取用户统计信息
export const getUserStats = () => {
  return request({
    method: "get",
    url: "user/getUserStats",
  });
};

// 更新用户信息
export const updateUser = (data) => {
  return request({
    method: "put",
    url: "user/updateUser",
    data
  });
};
// 用户打卡
export const checkin = () => {
  return request({
    method: "post",
    url: "user/checkin",
  });
};
// 获取帮助文档列表
export const getHelpList = () => {
  return request({
    method: "get",
    url: "help/list",
  });
};
//获取消息
export const getMessage = () =>{
  return request({
      method:'get',
      url:'message/getMessage'
  })
}

// 根据ID获取帮助文档详情
export const getHelpById = (id) => {
  return request({
    method: "get",
    url: `help/${id}`,
  });
};
// 提交用户反馈
export const submitFeedback = (data) => {
  return request({
    method: "post",
    url: "feedback/submit",
    data
  });
};
// 注销账号
export const revokeAccount = () => {
  return request({
    method: "delete",
    url: "user/revokeAccount",
  });
};

//上传图片
export const uploadImageApi = (formData) => {
  return request({
    method: "post",
    url: 'file/image',
    data: formData,
    headers: {
      "Content-Type": "multipart/form-data",
    },
    timeout: 60000,
  });
};
// 获取资产列表
export const getPropertyList = () => {
  return request({
    method: "get",
    url: "property",
  });
}

// 添加资产
export const addProperty = (data) => {
  return request({
    method: "post",
    url: "property",
    data
  });
}

// 更新资产
export const updateProperty = (id, data) => {
  return request({
    method: "put",
    url: `property/${id}`,
    data
  });
}

// 删除资产
export const deleteProperty = (id) => {
  return request({
    method: "delete",
    url: `property/${id}`
  });
}

// 获取图表数据
export const getChartData = (params) => {
  return request({
    method: "get",
    url: "tally/data",
    params // { type: 'expense/income', period: 'week/month/year' }
  });
}

// 获取排行榜数据
export const getRankingData = (params) => {
  return request({
    method: "get",
    url: "tally/ranking",
    params // { type: 'expense/income', period: 'week/month/year' }
  });
}

// 获取账单明细
export const getBillDetail = (params) => {
  return request({
    method: "get",
    url: "tally/detail",
    params // { year: 2025, month: 10 }
  });
}

// 保存记账记录
export const saveTallyRecord = (data) => {
  return request({
    method: "post",
    url: "tally/save",
    data // { type: 1, flag: 1, price: 50, remark: '' }
  });
}

// 更新记账记录
export const updateTallyRecord = (id, data) => {
  return request({
    method: "put",
    url: `tally/update/${id}`,
    data // { type: 1, flag: 1, price: 50, remark: '', createTime: timestamp }
  });
}

// 删除记账记录
export const deleteTallyRecord = (id) => {
  return request({
    method: "delete",
    url: `tally/delete/${id}`
  });
}

// 获取账户概览
export const getAccountOverview = () => {
  return request({
    method: "get",
    url: "tally/overview"
  });
}

// 获取账本列表
export const getAccountList = () => {
  return request({
    method: "get",
    url: "account/list"
  });
}

// 根据ID获取账本详情
export const getAccountById = (id) => {
  return request({
    method: "get",
    url: `account/${id}`
  });
}

// 创建新账本
export const createAccount = (data) => {
  return request({
    method: "post",
    url: "account",
    data // { categoryId, type, remark }
  });
}

// 更新账本
export const updateAccount = (id, data) => {
  return request({
    method: "put",
    url: `account/${id}`,
    data
  });
}

// 删除账本
export const deleteAccount = (id) => {
  return request({
    method: "delete",
    url: `account/${id}`
  });
}

// 获取指定账本的记账明细
export const getAccountTallyList = (params) => {
  return request({
    method: "get",
    url: "tally/detail",
    params // { accountId, year, month }
  });
}